<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <link rel="stylesheet" href="../../css/style.css" />
    <link rel="stylesheet" href="../../css/element.css?v=1">
    <script src="../../js/zyrpublic.js?v=1.0"></script>
    <script src="../../js/zyrfunction.js?v=1.0"></script>
    <script src="../../javascript/vue.js"></script>
    <script src="../../javascript/elementui.js"></script>
    <script src="../../javascript/axios.min.js"></script>
</head>

<body>
    <div class="page-wrap" id="app">
        <section class="page-hd t">
            <header>
                <h5 class="title">
                    <a href="#" class="red">秒杀列表</a>
                </h5>
            </header>
            <hr />
        </section>

        <div class="flex flex-wrap flex-col-6 form-group">
            <div class="box-child text-left margin_left10">
                <input onclick="DeleteInfoList(this);" data-info="DeletedCpilke" type="button" value="批量删除"
                    class="btn btn-info" />
                <input onclick="window.location.href='addCpike.html'" type="button" value="添加" class="btn btn-info" />
            </div>
            <div class="box-child text-left" style="margin-left: 20px">
                活动商品状态：
                <select style="width: auto" id="activitiesState" onchange="SearchInfo()">
                    <option value="-1">请选择</option>
                    <option value="1">未开始</option>
                    <option value="2">进行中</option>
                    <option value="3">已结束</option>
                </select>
            </div>
            <div class="box-child text-left" style="margin-left: 20px; display: flex; align-items: center">
                <span class="font_size16 red" style="margin-right: 20px">首页开启</span>
                <el-switch v-model="cpikeVal" active-color="#13ce66" inactive-color="#000"
                    @change="handleSwitchChange(cpikeVal)">
                </el-switch>
            </div>
        </div>

        <div class="panel panel-default" style="text-align: center">
            <table class="table table-bordered" id="tableInfo">
                <thead>
                    <tr>
                        <th>
                            <input type="checkbox" class="aceParent" id="all" />
                        </th>
                        <th>秒杀ID</th>
                        <th>秒杀名称</th>
                        <th>商品图片</th>
                        <th>商品名称</th>
                        <th>开始时间</th>
                        <th>结束时间</th>
                        <th>商品数量</th>
                        <th>排序</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>

            <div id="page"></div>
        </div>
    </div>
    <!---page-wrap------>
</body>

<script>
    var instance = axios.create({
        baseURL: httpurl,
        timeout: 3000,
        headers: {
            'Content-Type': 'application/json',
            "Authorization": GetTokenInfo()
        }
    })
</script>

<script>

    var app = new Vue({
        el: "#app",
        data() {
            return {
                cpikeVal: false,
                statusList: []
            };
        },

        mounted() {

            // this.getquerySysDicOne();
            this.getquerySysDicList()
            // this.$nextTick(() => {
            //   this.cpikeVal =
            //     localStorage.getItem("cpikeFlag") == "true" ? true : false;
            //   console.log(this.cpikeVal, "mounted");
            // });
        },

        methods: {

            getquerySysDicList() {
                instance.get('querySysDicList?type=activity.open.status').then(res => {
                    console.log(res);
                    if (res.data.rtnCode == 200) {
                        console.log(res.data.data);
                        let list = res.data.data
                        this.statusList = list
                        list.forEach(v => {
                            if (v.code == 1) {
                                this.$nextTick(() => {
                                    this.cpikeVal = v.value == 1 ? true : false
                                })
                            }
                        })
                    }
                })
            },

            getquerySysDicOne(type) {
                let query = {
                    code: 1,
                    value: type
                }
                instance.post(`/updateActivityState`,
                    query
                ).then(res => {
                     if(res.data.rtnCode == 200){
                          this.$message.success('修改成功');
                    }
                     if(res.data.rtnCode == 500){
                         this.cpikeVal = false
                         this.$message.error('其他活动已开启');
                    }
                }).catch(err => {
                    console.log(err);
                })
            },

            handleSwitchChange(e) {
              let type = e == true ? 1 : 0
               this.getquerySysDicOne(type)
                // if (spellFlag) {
                //     this.cpikeVal = false;
                //     this.$message.error("拼单和秒杀不能同时开启");
                //     return;
                // }
               
            },
        },
    });
</script>

</html>